﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WFNetLib;
using WFNetLib.WeiXin;
using System.Net;
using System.IO;

namespace 平台接口软件
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
//             Dictionary<string, string> newHeaders=new Dictionary<string, string>();
//             newHeaders.Add("","");
            WFHttpWebResponse WebResponse = new WFHttpWebResponse();
            HttpWebResponse hr = WebResponse.CreateGetHttpResponse("https://api.weixin.qq.com/cgi-bin/menu/get?access_token=" + BaseSupport.access_token.value);
            textBox1.AppendText(WebResponse.Content + "\r\n");
        }
        private void Form1_Load(object sender, EventArgs e)
        {            
//             BaseSupport.appID = "wx3e14799ff51aa931";
//             BaseSupport.appsecret = "adfeaa10f2fea5a2818c253f136740b2";
            //永平-物联温度计
            BaseSupport.appID = "wxbba1bb873498618b";
            BaseSupport.appsecret = "a60cd90f5dbe9d3aeef3860c2c12ef05";
            BaseSupport.RefreshAccessToken(DateTime.Now);
            textBox2.Text = BaseSupport.access_token.value;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FileStream fs1 = new FileStream("物联温度计.txt", FileMode.Open);
            StreamReader sr = new StreamReader(fs1, Encoding.GetEncoding("GBK"));
            string menu = sr.ReadToEnd();
            sr.Close();
            fs1.Close();
            WFHttpWebResponse WebResponse = new WFHttpWebResponse();
            HttpWebResponse hr = WebResponse.CreatePostHttpResponse("https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + BaseSupport.access_token.value, Encoding.UTF8.GetBytes(menu));
            textBox1.AppendText(WebResponse.Content + "\r\n");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            WFHttpWebResponse WebResponse = new WFHttpWebResponse();
            HttpWebResponse hr = WebResponse.CreateGetHttpResponse("https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=" + BaseSupport.access_token.value);
            textBox1.AppendText(WebResponse.Content + "\r\n");
        }

        private void button4_Click(object sender, EventArgs e)
        {
            WFHttpWebResponse WebResponse = new WFHttpWebResponse();
            HttpWebResponse hr = WebResponse.CreateGetHttpResponse("https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token=" + BaseSupport.access_token.value);
            textBox1.AppendText(WebResponse.Content + "\r\n");
        }
    }
}
